package backend.model.admin;

import backend.model.base.DBModel;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import javax.persistence.*;

@NamedQueries({ @NamedQuery(name = "findAllProjects", query = "from Project"),
                @NamedQuery(name = "findAllActiveProjects", query = "from Project where isActive = true"),
                @NamedQuery(name = "findAllActiveAndDirectPaymentProjects", query = "from Project where isActive = true and isDirectPayment = true"),
                @NamedQuery(name = "findProjectByName", query = "from Project where name = :name"),
                @NamedQuery(name = "findDistinctProjectBookedForDate", query = "select distinct project from WorkLog where date = :date")
})
@Entity
@Table(name = "project")
public class Project extends DBModel {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private int id;

	@Column(name = "name")
	private String name;

	@Column(name = "description")
	private String description;

	@Column(name = "is_active")
	private boolean isActive;

    @Column(name = "is_direct_payment")
    private boolean isDirectPayment;

    @ManyToOne
    @JoinColumn(name = "pm_romania_id")
    private Employee pmRomania;

    @ManyToOne
    @JoinColumn(name = "pm_norway_id")
    private ForeignManager pmNorway;

	@Override
    public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(boolean isActive) {
		this.isActive = isActive;
	}

    public boolean getIsDirectPayment() {
        return isDirectPayment;
    }

    public void setIsDirectPayment(boolean isDirectPayment) {
        this.isDirectPayment = isDirectPayment;
    }

    public Employee getPmRomania() {
        return pmRomania;
    }

    public void setPmRomania(Employee pmRomania) {
        this.pmRomania = pmRomania;
    }

    public ForeignManager getPmNorway() {
        return pmNorway;
    }

    public void setPmNorway(ForeignManager pmNorway) {
        this.pmNorway = pmNorway;
    }

    @Override
    public String getDisplayLabel() {
		return name;
	}

	@Override
    public int compareTo(Object o) {
		if (!(o instanceof Project)) {
			return -1;
		} else {
			Project otherProject = (Project) o;
			return getDisplayLabel().compareTo(otherProject.getDisplayLabel());
		}
	}
}